package br.ufc.parser;

public class Predicate {

	private String attribute;
	private String operation;
	private Value value;
	public Predicate(String attribute, String operation, String value) {
		super();
		this.attribute = attribute;
		this.operation = operation;
		this.value = new Value(value);
	}
	public Predicate(String attribute, String operation, Double value) {
		super();
		this.attribute = attribute;
		this.operation = operation;
		this.value = new Value(value);
	}
	public Predicate(String attribute, String operation, Value value) {
		super();
		this.attribute = attribute;
		this.operation = operation;
		this.value = value;
	}
	public String getAttribute() {
		return attribute;
	}
	public String getOperation() {
		return operation;
	}
	public Value getValue() {
		return this.value;
	}
	public double getDoubleValue() {
		return this.value.getDoubleValue();
	}
	public String getStringValue() {
		return this.value.getStringValue();
	}
	public String toString(){
		return this.attribute + " " + this.operation + " " + this.value.toString();
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((attribute == null) ? 0 : attribute.hashCode());
		result = prime * result
				+ ((operation == null) ? 0 : operation.hashCode());
		result = prime * result + ((value == null) ? 0 : value.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Predicate other = (Predicate) obj;
		if (attribute == null) {
			if (other.attribute != null)
				return false;
		} else if (!attribute.equals(other.attribute))
			return false;
		if (operation == null) {
			if (other.operation != null)
				return false;
		} else if (!operation.equals(other.operation))
			return false;
		if (value == null) {
			if (other.value != null)
				return false;
		} else if (!value.equals(other.value))
			return false;
		return true;
	}
}
